<template>
  <div class="medicalInformation">
    <ul v-for="(list, index) in currentList" :key="index" class="medicalContent">
      <li v-for="(key, _index) in list.keys" :key="list.keys[_index]">{{list[key]}}</li>
      <div @click="showAll(index)" v-if="index === currentRenderKey">收起</div>
      <div @click="showAll(index)" v-else>展开</div>
    </ul>
  </div>
</template>

<script>
export default {
  name: "medicalInformation",
  computed: {
    currentList() {
      return this.list.map((item, index) => {
        let keys = Object.keys(item);
        keys =
          index === this.currentRenderKey
            ? keys
            : keys.filter((key, index) => index < 2);
        let newObj = {};
        keys.forEach(key => (newObj[key] = item[key]));
        newObj.keys = keys;
        return newObj;
      });
    }
  },
  data() {
    return {
      operator: '展开',
      currentRenderKey: null,
      list: [
        {
          first: 1,
          second: 2,
          third: 3,
          forth: 4
        },
        {
          first: 1,
          second: 2,
          third: 3,
          forth: 4
        }
      ]
    };
  },
  methods: {
    showAll(index) {
      if (this.currentRenderKey === index) {
        index = null;
      }
      this.currentRenderKey = index;
    }
  }
};
</script>

<style lang="scss" scoped>
.medicalInformation {
  position: absolute;
  width: 100%;
  height: 100%;
  background-color: #f3f1f4;
  padding: 40rpx 20rpx;
  box-sizing: border-box;
  .medicalContent {
    background: #ffffff;
    border-radius: 10rpx;
    box-sizing: border-box;
    margin-bottom: 20rpx;
    padding: 20rpx;
    li {
      width: 100%;
      line-height: 60rpx;
    }
  }
}
</style>